pygrub currently takes a file on the command line to mean a config file
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Sun, 26 Feb 2006 09:54:06 +0000 (10:54 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Sun, 26 Feb 2006 09:54:06 +0000 (10:54 +0100)
if it can't figure out partitions and filesystems.  This then makes it
balloon to absurd sizes.  Make this only happen if you pass a debugging
flag

Signed-off-by: Jeremy Katz <katzj@redhat.com>
tools/pygrub/src/pygrub

index e0a5d31fdce649f8e315276726f1b80b13e6a74d..9b94653284ca851d4e76ffead38ad95d4a192cc3 100644 (file)
@@ -94,12 +94,18 @@ def get_active_offset(file):
             return struct.unpack("<L", buf[poff+8:poff+12])[0] * SECTOR_SIZE
     return -1
 
-def get_config(fn):
+def get_config(fn, isconfig = False):
     if not os.access(fn, os.R_OK):
         raise RuntimeError, "Unable to access %s" %(fn,)
 
     cf = grub.GrubConf.GrubConfigFile()
 
+    if isconfig:
+        # set the config file and parse it
+        cf.filename = fn
+        cf.parse()
+        return cf
+
     offset = 0
     if is_disk_image(fn):
         offset = get_active_offset(fn)
@@ -130,9 +136,7 @@ def get_config(fn):
         # then parse the grub config
         cf.parse(buf)
     else:
-        # set the config file and parse it
-        cf.filename = fn
-        cf.parse()
+        raise RuntimeError, "Unable to read filesystem" 
     
     return cf
 
@@ -214,7 +218,8 @@ if __name__ == "__main__":
 
     try:
         opts, args = getopt.gnu_getopt(sys.argv[1:], 'qh::',
-                                   ["quiet", "help", "output=", "entry="])
+                                   ["quiet", "help", "output=", "entry=",
+                                    "isconfig"])
     except getopt.GetoptError:
         usage()
         sys.exit(1)
@@ -227,6 +232,7 @@ if __name__ == "__main__":
     output = None
     entry = None
     interactive = True
+    isconfig = False
     for o, a in opts:
         if o in ("-q", "--quiet"):
             interactive = False
@@ -239,13 +245,15 @@ if __name__ == "__main__":
             entry = a
             # specifying the entry to boot implies non-interactive
             interactive = False
+        elif o in ("--isconfig",):
+            isconfig = True
 
     if output is None or output == "-":
         fd = sys.stdout.fileno()
     else:
         fd = os.open(output, os.O_WRONLY)
 
-    cf = get_config(file)
+    cf = get_config(file, isconfig)
     if interactive:
         curses.wrapper(run_main)
     else: